package com.example.main;

import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.KeyEvent;

import com.hoho.android.usbserial.driver.UsbSerialDriver;
import com.hoho.android.usbserial.driver.UsbSerialPort;
import com.hoho.android.usbserial.driver.UsbSerialProber;
import com.hoho.android.usbserial.util.SerialInputOutputManager;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.Executors;


public class ScanGunActivity4 extends FragmentActivity {

    private static final String TAG = "ScanGunActivity4";

    private DispatchKeyResolver dispatchKeyResolver = new DispatchKeyResolver();
    private ScanGunKeyEventHelper mScanGunKeyEventHelper = new ScanGunKeyEventHelper();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scan_gun);
        dispatchKeyResolver.setKeyInputListener(new DispatchKeyResolver.OnKeyInputListener() {
            @Override
            public void onKeyInput(char aChar) {
                Log.i(TAG, "onKeyInput: " + aChar);
            }
        });

        mScanGunKeyEventHelper.setOnBarCodeCatchListener(new ScanGunKeyEventHelper.OnScanSuccessListener() {
            @Override
            public void onScanSuccess(String barcode) {
                Log.i(TAG, "onScanSuccess: " + barcode);
            }
        });
    }

    @SuppressLint("RestrictedApi")
    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
//            dispatchKeyResolver.resolveKeyEvent(event);
            //dispatchKeyResolver.ddd(this,event);
            mScanGunKeyEventHelper.analysisKeyEvent(event);
        }

        return super.dispatchKeyEvent(event);
    }
}

